package dynamicProgramming;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class ReadOptimalBST {
	
	public static List<Map.Entry <String,Double>> readFile(String fileName){
		Scanner read = null;
		
		try{
			read = new Scanner(new File(fileName));
		} catch(FileNotFoundException e){
			e.printStackTrace();
		}
		
		String firstLine = read.nextLine();
		String[] firstLineToken = firstLine.split(" ");
		int size = Integer.parseInt(firstLineToken[0]);
		
	
		String line;
		String[] lineToken;
		
		Map<String,Double> map = new HashMap<String,Double>();
		
		int i=0;
		while(i<=size && read.hasNextLine()){
			line = read.nextLine();
			lineToken = line.split(" ");
			
			String key=lineToken[0];
			String value = lineToken[1];
			
			map.put(key, Double.parseDouble(value));
			
			
			i++;
			
		}
		

		List<Map.Entry <String,Double>> file = new ArrayList< Map.Entry<String,Double>>(map.entrySet());
	
		
		Collections.sort(file, new Comparator<Map.Entry <String,Double>>(){
			
			public int compare( Map.Entry <String,Double> o1, Map.Entry <String,Double> o2){
				
				return o1.getKey().compareTo(o2.getKey());
			}
			
		});

		
		
//		System.out.println(file);
		

		
		
		read.close();
		return file;
	}
	
	
	
	
	
	
	
	
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
	}

}
